package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.concurrent.CopyOnWriteArrayList;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.download.UpdateManager;
import com.handinfo.android.game.Cell;
import com.handinfo.android.game.GameMessage;
import com.handinfo.android.game.IconManger;
import com.handinfo.android.game.item.Item;
import com.handinfo.android.game.item.MailItem;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWCharsDetection;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWDragListener;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.DWLongListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWCheckbox;
import com.handinfo.android.uicontrols.controls.DWControl;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWGrid;
import com.handinfo.android.uicontrols.controls.DWGrids;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWInputBox;
import com.handinfo.android.uicontrols.controls.DWLabel;
import com.handinfo.android.uicontrols.controls.DWListSubItem;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWRadioButton;
import com.handinfo.android.uicontrols.controls.DWTabControl;
import com.handinfo.android.uicontrols.controls.DWTabPage;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UIMail implements IUIWindows
{

	public Bitmap m_cr_tab_1 = null;// 点击前图片
	public Bitmap m_cr_tab_2 = null;// 点击后图片
	public Bitmap m_cr_tuichu = null;// 叉键退出
	public Bitmap m_cr_choose_ture = null; ///下面的单选被选中时
	public Bitmap m_cr_choose_false = null;///下面的单选没被选中时
	public Bitmap m_cr_mail_1 = null;//有金钱或者礼物时的图片提示
	public Bitmap m_cr_mail_2 = null;///邮件未读的时候得图片提示
	public Bitmap m_cr_del_1 = null; ///删除单个邮件的按钮按下前
	public Bitmap m_cr_del_2 = null; ///删除单个邮件的按钮按下后抬起前
	public Bitmap m_cr_grid = null;
	public Bitmap m_cr_but1 = null;
	public Bitmap m_cr_but12 = null;
	public Bitmap m_cr_fy_1 = null;
	public Bitmap m_cr_fy_2 = null;
	public Bitmap m_cr_tit = null;
	public Bitmap m_cr_tit_shouxin = null;
	public Bitmap m_cr_gm_but = null;
	public Bitmap m_cr_gm_but_anxia = null;

	public DWImageBox m_tit_ima_mail;
	public DWImageBox m_tit_shouxin_ima;
	public DWFrame m_mail_Frame = null; // ///画布
	public DWTitle m_mail_tit;// /标题

	public DWBackground m_xbj_bg;// /小背景

	public DWListbox m_listbox;// //listbox
	public DWListSubItem m_lsi[];
	public DWTextbox m_biaoti_tb[] = new DWTextbox[10];// //标题下的第一列的textbox
	public DWTextbox m_name_tb[] = new DWTextbox[10];// //姓名下的第二列的textbox
	public DWTextbox m_shijian_tb[] = new DWTextbox[3];// ///时间下的第三列的textbox
	public DWImageBox m_tuichu_ima; ////退出
	public DWTabControl m_tabcontrol = null; /////标签容器的定义
	public String[] m_stringname = new String[] { "收信", "发信", "客服" }; ////标签页的标签内容
	public String[] m_stringlab = new String[] { "标题", "姓名", "日期" };
	public String[] m_string_choose_name = new String[] { "全部", "未读" };

	public DWTabPage m_tp[] = new DWTabPage[m_stringname.length]; ////标签页的定义
	public DWLabel m_label[] = new DWLabel[m_stringlab.length];
	public DWLabel m_biaoti_lb;
	public DWLabel m_name_lb;
	public DWLabel m_shijian_lb;

	public DWLabel m_send_tit_lb; ////标题标签
	public DWTextbox m_send_tit_tb;
	public DWLabel m_send_recv_lb;////收件人标签
	public DWTextbox m_send_recv_tb;
	public DWLabel m_send_content_lb;////内容标签
	public DWTextbox m_send_content_tb;
	public DWLabel m_send_item_lb;////附件标签
	public DWTextbox m_send_item_tb;
	public DWLabel m_send_money_lb;////金钱标签
	public DWTextbox m_send_money_tb;

	public DWInputBox m_send_tit_ib;////标题输入框
	public DWInputBox m_send_recv_ib;////收件人的输入框
	public DWInputBox m_send_content_ib;////内容的输入框
	public DWGrid m_send_item_grid;////附件输入框
	public DWInputBox m_send_money_ib;////金钱输入框

	public DWButton m_add_but; ////添加好友按钮
	public DWButton m_send_but; ////发送按钮

	///客服的
	public DWButton m_send_GM_but;
	public DWLabel m_send_GM_tit_lb;
	public DWInputBox m_send_GM_tit_ib;
	public DWLabel m_send_GM_recv_lb;
	public DWLabel m_send_GM_recv_ib;
	public DWLabel m_send_GM_content_lb;
	public DWInputBox m_send_GM_content_ib;

	public DWRadioButton m_chooseRadioButton;
	public DWLabel m_textbox[];////3个标签下的textbox
	public DWTextbox m_choose_textbox[] = new DWTextbox[m_string_choose_name.length];
	public DWTextbox m_item_text;
	public DWTextbox m_item_information_text;
	public byte m_type;//显示类型
	protected MailItem m_sendMail = new MailItem();
	protected Hashtable<Long, MailItem> m_recive = new Hashtable<Long, MailItem>();//删除道具的存储器
	protected MailItem[] m_present;///根据这个数组里的每个对象里的道具和金钱是否为空判断用哪个图片
	int m_label_index;
	IconManger m_iconmanger = new IconManger();
	Boolean m_flag;
	Cell m_cell;
	DWButton m_del_1;
	DWButton m_all_del_but_2;
	public String m_friend_name;
	DWLabel m_l = new DWLabel("测试");
	DWInputBox m_choose_ib;
	DWFrame m_choose_frame = null;
	Cell m_item_cell;
	Boolean m_grid_flag;
	public Bitmap m_cr_shuaxin = null;
	public Bitmap m_cr_shuaxin_xia = null;
	float wide = DWFont.getDefaultFont().stringWidth("国");
	public void Mail()
	{
		if (DWControlsManager.getInstance().contains(m_mail_Frame)) {
			if (m_mail_Frame != null) {
				DWControlsManager.getInstance().removeControl(m_mail_Frame);
			}
		}

		// ////画布（大背景）
		m_mail_Frame = new DWFrame(DWFrame.FRAME_TYPE_HALF_LEFT,
				true);
		m_mail_Frame.setClickClose(false);
		// /////标题
		m_mail_tit = new DWTitle("", m_mail_Frame);
		m_mail_Frame.addControl(m_mail_tit);
		m_tit_ima_mail = new DWImageBox(m_cr_tit);
		m_tit_ima_mail.setNearAnchor(m_mail_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_mail_Frame.addControl(m_tit_ima_mail);
		// //小背景
		m_xbj_bg = new DWBackground(
				m_mail_Frame.getShowWidth() - 20,
				m_mail_Frame.getShowHeight() - (m_mail_tit.getShowHeight() - 20) - m_cr_tab_2.getHeight() - 20);
		m_xbj_bg.setNearAnchor(m_mail_Frame, Tools.LEFT_TOP,
				Tools.LEFT_TOP, 10, m_cr_tab_2.getHeight() + (m_mail_tit.getShowHeight() - 20));
		m_xbj_bg.setFill(false);
		m_mail_Frame.addControl(m_xbj_bg);

		// ///标签页、标签容器  左右15 上下
		m_tabcontrol = new DWTabControl(m_cr_tab_1, m_cr_tab_2, m_xbj_bg.getShowWidth(), m_xbj_bg.getShowHeight()
				+ m_cr_tab_2.getHeight() - 10);
		m_tabcontrol.setNearAnchor(m_xbj_bg, Tools.LEFT_TOP, Tools.LEFT_TOP, 5, -m_cr_tab_2.getHeight());
		m_mail_Frame.addControl(m_tabcontrol);

		// //退出图片按钮
		m_tuichu_ima = new DWImageBox(m_cr_tuichu);
		m_tuichu_ima.setNearAnchorUn(m_mail_tit, Tools.RIGHT_VCENTER,
				Tools.RIGHT_VCENTER, 0, 0);
		m_tuichu_ima.addListener(m_tuichu_lis);
		m_tuichu_ima.setTouchZoomIn(40, 40);
		m_mail_Frame.addControl(m_tuichu_ima);
		for (int m_tp_index = 0; m_tp_index < m_stringname.length; m_tp_index++) {
			m_tp[m_tp_index] = new DWTabPage();
			m_tp[m_tp_index].setName(m_stringname[m_tp_index]);
			DWCheckbox m_ch = new DWCheckbox();
			if (m_tp_index == 0) {
				////标题  发件人  时间的三个标签 布局
				for (int m_label_index = 0; m_label_index < m_stringlab.length; m_label_index++) {
					m_label[m_label_index] = new DWLabel(m_stringlab[m_label_index]);
					m_label[m_label_index].setBackgroundColor(Tools.ALPHA);
					m_label[m_label_index].setTextColor(Tools.ORANGE);
					m_label[m_label_index].setShowWideHigh((m_tabcontrol.getShowWidth() - 10 - m_cr_mail_1.getWidth()
							- m_cr_mail_2.getWidth() - m_ch.getShowWidth()) / 3, m_label[m_label_index].getShowHeight());
					if (m_label_index == 0) {
						m_label[m_label_index].setNearAnchor(m_tp[m_tp_index], Tools.LEFT_TOP, Tools.LEFT_TOP,
								m_ch.getShowWidth(), 10);
					}
					else {
						m_label[m_label_index].setNearAnchor(m_label[m_label_index - 1], Tools.LEFT_TOP,Tools.RIGHT_TOP,0, 0);
					}
					m_tp[m_tp_index].addControls(m_label[m_label_index]);
				}

				//////listbox  布局
				m_listbox = new DWListbox(m_tabcontrol.getShowWidth() - 10, m_tabcontrol.getShowHeight()
						- m_cr_tab_2.getHeight()
						- m_label[0].getShowHeight() - m_cr_but_3.getHeight() - 25);
				m_listbox.setNearAnchor(m_tp[m_tp_index], Tools.LEFT_TOP, Tools.LEFT_TOP, 0,
						m_label[0].getShowHeight() + 10);
				m_listbox.setLineSpacing(10);

				UpdataMail(MailItem.收件显示_全部);

				DWTextbox m_text = new DWTextbox("全部");
				String m_tpname[] = new String[] { "全部", "未读" };
				m_chooseRadioButton = new DWRadioButton(m_tpname, 2, m_cr_choose_ture.getWidth()
						+ m_text.getShowWidth() + 5, m_cr_choose_ture.getHeight(), m_cr_choose_false,
						m_cr_choose_ture);
				m_chooseRadioButton.setNearAnchor(m_tp[m_tp_index], Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 5, -5);
				m_tp[m_tp_index].addControls(m_chooseRadioButton);
				m_chooseRadioButton.addListener(m_chooseRadioButton_lis);

				////之前是在这里和上一个监听连接
				//2个按钮
				m_del_1 = new DWButton("删除", m_cr_but_3);
				m_del_1.setDownImage(m_cr_but_4);
				m_del_1.setNearAnchor(m_chooseRadioButton, Tools.LEFT_BOTTOM, Tools.RIGHT_BOTTOM, (m_tabcontrol
						.getShowWidth()
						- m_chooseRadioButton.getShowWidth() - 2 * m_cr_but_3.getWidth()) / 3, 0);
				m_del_1.addListener(m_del_1_lis);

				m_flag = true;
				m_all_del_but_2 = new DWButton("全选", m_cr_but_3);
				m_all_del_but_2.setDownImage(m_cr_but_4);
				m_all_del_but_2
						.setNearAnchor(m_del_1, Tools.LEFT_TOP, Tools.RIGHT_TOP,
								(m_tabcontrol.getShowWidth() - m_chooseRadioButton.getShowWidth() - 2 * m_cr_but_3
										.getWidth()) / 3, 0);
				m_all_del_but_2.addListener(m_all_del_but_2_lis);

				DWButton m_new_mail_but = new DWButton("", m_cr_shuaxin);
				m_new_mail_but.setDownImage(m_cr_shuaxin_xia);
				m_new_mail_but.setNearAnchor(m_label[2], Tools.LEFT_BOTTOM, Tools.RIGHT_BOTTOM, 8, 0);
				m_new_mail_but.setTouchZoomIn(20, 0);
				m_new_mail_but.addListener(m_new_mail_lis);
				
				m_tp[m_tp_index].addControls(m_listbox);
				m_tp[m_tp_index].addControls(m_del_1);
				m_tp[m_tp_index].addControls(m_all_del_but_2);
				m_tp[m_tp_index].addControls(m_new_mail_but);
				m_tabcontrol.addTabPage(m_tp[m_tp_index]);
			}
			else if (m_tp_index == 1) {
				/////标题
				/////////标签
				m_send_tit_lb = new DWLabel("");
				m_send_tit_lb.setBackgroundColor(Tools.ALPHA);
				m_send_tit_lb.setShowWideHigh(2 * (int) wide, DWFont.getDefaultFont().getHeight()+5);
				int m_y = (m_xbj_bg.getShowHeight()-10-3*m_send_tit_lb.getShowHeight()-2-(m_xbj_bg.getShowHeight()-10)/3-m_cr_grid.getHeight()-m_cr_but1.getHeight())/6;
				Tools.debugPrintln("m_y:"+m_y);
				m_send_tit_lb.setNearAnchor(m_tp[m_tabcontrol.getPageIndex()], Tools.LEFT_TOP, Tools.LEFT_TOP, 10, m_y);
				
				m_send_tit_tb = new DWTextbox("<mark c=ffc001>" + "标题" + "</mark>");
				m_send_tit_tb.setNearAnchor(m_send_tit_lb, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

				////////输入框
				m_send_tit_ib = new DWInputBox(10*DWFont.getDefaultFont().getFontSize(), DWFont.getDefaultFont().getHeight()+5, m_mail_Frame);
				m_send_tit_ib.setNearAnchor(m_send_tit_lb, Tools.LEFT_TOP, Tools.RIGHT_TOP, 5, 0);

				DWTextbox m_tb = new DWTextbox("<mark c=ffc001>" + "(限9字)" + "</mark>");
				m_tb.setNearAnchor(m_send_tit_ib, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);

				////////收件人
				////////收件人标签
				m_send_recv_lb = new DWLabel("");
				m_send_recv_lb.setBackgroundColor(Tools.ALPHA);
				m_send_recv_lb.setShowWideHigh(3 * (int) wide, DWFont.getDefaultFont().getHeight()+5);
				m_send_recv_lb.setNearAnchor(m_send_tit_lb, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, m_y);

				m_send_recv_tb = new DWTextbox("<mark c=ffc001>" + "收件人" + "</mark>");
				m_send_recv_tb.setNearAnchor(m_send_recv_lb, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

				////////收件人输入框
				m_send_recv_ib = new DWInputBox(8*DWFont.getDefaultFont().getFontSize(), DWFont.getDefaultFont().getHeight()+5, m_mail_Frame);
				m_send_recv_ib.setNearAnchor(m_send_recv_lb, Tools.LEFT_TOP, Tools.RIGHT_TOP, 5, 0);

				////////内容
				////////内容标签
				m_send_content_lb = new DWLabel("");
				m_send_content_lb.setBackgroundColor(Tools.ALPHA);
				m_send_content_lb.setShowWideHigh(2 * (int) wide, DWFont.getDefaultFont().getHeight()+5);
				m_send_content_lb.setNearAnchor(m_send_recv_lb, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, m_y);

				m_send_content_tb = new DWTextbox("<mark c=ffc001>" + "内容" + "</mark>");
				m_send_content_tb.setNearAnchor(m_send_content_lb, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

				////////内容输入框
				m_send_content_ib = new DWInputBox(m_tabcontrol.getShowWidth() - 30, (m_xbj_bg.getShowHeight()-10) / 3,
						m_mail_Frame);
				m_send_content_ib.setNearAnchor(m_send_content_lb, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 2);

				////////附件
				////////附件标签
				m_send_item_lb = new DWLabel("");
				m_send_item_lb.setBackgroundColor(Tools.ALPHA);
				m_send_item_lb.setShowWideHigh(2 * (int) wide, DWFont.getDefaultFont().getHeight()+5);

				m_send_item_tb = new DWTextbox("<mark c=ffc001>" + "附件" + "</mark>");
				m_send_item_tb.setNearAnchor(m_send_item_lb, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

				////////附件格子
				m_send_item_grid = new DWGrid(m_cr_grid);
				m_send_item_lb.setNearAnchor(m_send_content_ib, Tools.LEFT_TOP, Tools.LEFT_BOTTOM,
						0, m_send_item_grid.getShowHeight() - m_send_item_lb.getShowHeight() + m_y);

				m_send_item_grid.setNearAnchor(m_send_item_lb, Tools.LEFT_BOTTOM, Tools.RIGHT_BOTTOM, 5, 0);

				m_send_item_grid.addListener(m_grid_lis);
				m_send_item_grid.addDragListener(new DWDragListener() {

					public void OnDrag(DWControl control)
					{
						if (control instanceof DWGrids)
						{
							if (((DWGrids) control).getTouchGrid().m_data != null)
							{
								m_item_cell = ((Cell) ((DWGrids) control).getTouchGrid().m_data).Clone();
								if (m_item_cell != null) {
									Choose();
								}
								if (m_send_item_grid.m_data == null)
								{
									m_item_cell = null;
								}
							}
						}
					}
				});

				m_send_item_grid.addLongListener(new DWLongListener() {

					public void OnLong(boolean isDown)
					{
						if (isDown == true)
						{
							m_grid_flag = true;
						}
						else if (isDown == false)
						{
							m_grid_flag = false;
						}
					}
				});

				m_item_text = new DWTextbox("", 200);
				m_item_text.setNearAnchor(m_send_item_grid, Tools.LEFT_BOTTOM, Tools.RIGHT_BOTTOM, 5, 0);

				////////金钱
				////////金钱标签
				m_send_money_lb = new DWLabel("");
				m_send_money_lb.setBackgroundColor(Tools.ALPHA);
				m_send_money_lb.setShowWideHigh(2 * (int) wide, 30);
				m_send_money_lb.setNearAnchor(m_send_item_lb, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 15);

				m_send_money_tb = new DWTextbox("<mark c=ffc001>" + "金钱" + "</mark>");
				m_send_money_tb.setNearAnchor(m_send_money_lb, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

				////////金钱输入框
				m_send_money_ib = new DWInputBox(180, m_send_money_lb.getShowHeight(), m_mail_Frame);
				m_send_money_ib.setNearAnchor(m_send_money_lb, Tools.LEFT_TOP, Tools.RIGHT_TOP, 5, 0);

				//////添加好友按钮
				m_add_but = new DWButton("添好友", m_cr_but_3);
				m_add_but.setDownImage(m_cr_but_4);
				m_add_but.setNearAnchor(m_send_recv_ib, Tools.LEFT_TOP, Tools.RIGHT_TOP, 5, 0);
				m_add_but.addListener(m_add_but_lis);

				//////发送按钮
				m_send_but = new DWButton("发送", m_cr_but1);
				m_send_but.setDownImage(m_cr_but12);
				m_send_but.setNearAnchor(m_send_content_ib, Tools.RIGHT_TOP, Tools.RIGHT_BOTTOM, -20, (m_y+m_cr_grid.getHeight()+m_y));
				m_send_but.addListener(m_send_but_lis);

				m_tp[m_tp_index].addControls(m_send_tit_lb);
				m_tp[m_tp_index].addControls(m_send_tit_ib);
				m_tp[m_tp_index].addControls(m_tb);
				m_tp[m_tp_index].addControls(m_send_recv_lb);
				m_tp[m_tp_index].addControls(m_send_recv_ib);
				m_tp[m_tp_index].addControls(m_send_content_lb);
				m_tp[m_tp_index].addControls(m_send_content_ib);
				m_tp[m_tp_index].addControls(m_send_item_lb);
				m_tp[m_tp_index].addControls(m_send_item_grid);
				m_tp[m_tp_index].addControls(m_item_text);
//				m_tp[m_tp_index].addControls(m_send_money_lb);
//				m_tp[m_tp_index].addControls(m_send_money_ib);
				m_tp[m_tp_index].addControls(m_add_but);
				m_tp[m_tp_index].addControls(m_send_but);
				m_tp[m_tp_index].addControls(m_send_tit_tb);
				m_tp[m_tp_index].addControls(m_send_recv_tb);
				m_tp[m_tp_index].addControls(m_send_content_tb);
				m_tp[m_tp_index].addControls(m_send_item_tb);
//				m_tp[m_tp_index].addControls(m_send_money_tb);
				m_tabcontrol.addTabPage(m_tp[m_tp_index]);
			}
			else if (m_tp_index == 2) {
				
				/////标题
				/////////标签
				m_send_GM_tit_lb = new DWLabel("");
				m_send_GM_tit_lb.setBackgroundColor(Tools.ALPHA);
				m_send_GM_tit_lb.setShowWideHigh(2 * (int) wide, DWFont.getDefaultFont().getHeight()+5);
				int m_y  = (m_xbj_bg.getShowHeight()-10-m_send_GM_tit_lb.getShowHeight()*3-m_cr_but1.getHeight()-(m_xbj_bg.getShowHeight()-10)/2-2)/5;
				m_send_GM_tit_lb.setNearAnchor(m_tp[m_tabcontrol.getPageIndex()], Tools.LEFT_TOP, Tools.LEFT_TOP, 10,
						m_y );

				DWTextbox m_tit_tb = new DWTextbox("<mark c=ffc001>" + "标题" + "</mark>");
				m_tit_tb.setNearAnchor(m_send_GM_tit_lb, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

				////////输入框
				m_send_GM_tit_ib = new DWInputBox(10*DWFont.getDefaultFont().getFontSize(), DWFont.getDefaultFont().getHeight()+5, m_mail_Frame);
				m_send_GM_tit_ib.setNearAnchor(m_send_GM_tit_lb, Tools.LEFT_TOP, Tools.RIGHT_TOP, 5, 0);

				DWTextbox m_tb = new DWTextbox("<mark c=ffc001>" + "(限9字)" + "</mark>");
				m_tb.setNearAnchor(m_send_GM_tit_ib, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);

				////////收件人
				////////收件人标签
				m_send_GM_recv_lb = new DWLabel("");
				m_send_GM_recv_lb.setBackgroundColor(Tools.ALPHA);
				m_send_GM_recv_lb.setShowWideHigh(3 * (int) wide, DWFont.getDefaultFont().getHeight()+5);
				m_send_GM_recv_lb.setNearAnchor(m_send_GM_tit_lb, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, m_y);

				DWTextbox m_recv_tb = new DWTextbox("<mark c=ffc001>" + "收件人" + "</mark>");
				m_recv_tb.setNearAnchor(m_send_GM_recv_lb, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

				////////收件人文本框
				m_send_GM_recv_ib = new DWLabel("GM");
				m_send_GM_recv_ib.setBackgroundColor(Tools.ALPHA);
				m_send_GM_recv_ib.setTextColor(0xFF00FF00);
				m_send_GM_recv_ib.setNearAnchor(m_send_GM_recv_lb, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);

				////////内容
				////////内容标签
				m_send_GM_content_lb = new DWLabel("");
				m_send_GM_content_lb.setBackgroundColor(Tools.ALPHA);
				m_send_GM_content_lb.setShowWideHigh(2 * (int) wide, DWFont.getDefaultFont().getHeight()+5);
				m_send_GM_content_lb.setNearAnchor(m_send_GM_recv_lb, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, m_y);

				DWTextbox m_content_tb = new DWTextbox("<mark c=ffc001>" + "内容" + "</mark>");
				m_content_tb.setNearAnchor(m_send_GM_content_lb, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

				////////内容输入框
				m_send_GM_content_ib = new DWInputBox(m_tabcontrol.getShowWidth() - 20,
						(m_xbj_bg.getShowHeight() - 10) / 2-10,
						m_mail_Frame);
				m_send_GM_content_ib.setNearAnchor(m_send_GM_content_lb, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 2);

				//////发送按钮
				m_send_GM_but = new DWButton("发送", m_cr_gm_but);
				m_send_GM_but.setDownImage(m_cr_gm_but_anxia);
				m_send_GM_but.setNearAnchor(m_send_GM_content_ib, Tools.RIGHT_TOP, Tools.RIGHT_BOTTOM, -20, m_y);
				m_send_GM_but.addListener(m_send_GM_but_lis);

				m_tp[m_tp_index].addControls(m_send_GM_tit_lb);
				m_tp[m_tp_index].addControls(m_send_GM_tit_ib);
				m_tp[m_tp_index].addControls(m_tb);
				m_tp[m_tp_index].addControls(m_send_GM_recv_lb);
				m_tp[m_tp_index].addControls(m_send_GM_recv_ib);
				m_tp[m_tp_index].addControls(m_send_GM_content_lb);
				m_tp[m_tp_index].addControls(m_send_GM_content_ib);
				m_tp[m_tp_index].addControls(m_send_GM_but);
				m_tp[m_tp_index].addControls(m_tit_tb);
				m_tp[m_tp_index].addControls(m_recv_tb);
				m_tp[m_tp_index].addControls(m_content_tb);
				m_tabcontrol.addTabPage(m_tp[m_tp_index]);
			}
		}

		DWControlsManager.getInstance().addControl(m_mail_Frame);
		if(!UIWindows.getInstance().m_main.m_tishi_mail_flag)
		{
			DWGameManager.getInstance().getSendMessage().sendRequestNewMails();
		}
	}

	private DWListener m_send_GM_but_lis = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			if (m_send_GM_tit_ib.getText() == null || m_send_GM_tit_ib.getText().equals(""))
			{
				DWGameManager.getInstance().showToast("标题不能为空。", 1000);
			}
			else
			{
				if (m_send_GM_tit_ib.getText().toString().length() > 9)
				{
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "标题内容的长度不能大于9。");
				}
				else
				{
					m_sendMail.m_title = m_send_GM_tit_ib.getText();
					m_sendMail.m_recvName = m_send_GM_recv_ib.getName();
					m_sendMail.m_content = m_send_GM_content_ib.getText();
					DWGameManager.getInstance().getSendMessage().sendMail(m_sendMail);
				}
			}
		}
	};
	private DWListener m_tuichu_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			DWControlsManager.getInstance().removeControl(m_mail_Frame);
			if (DWControlsManager.getInstance().contains(UIWindows.getInstance().m_social.m_si_fram))
			{
				UIWindows.getInstance().m_social.close((byte) 0);
			}
		}
	};

	private DWListener m_xq_tuichu_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			DWControlsManager.getInstance().removeControl(m_information_Frame);
		}
	};

//	private void Lock()
//	{
//		if (DWGameManager.getInstance().getSendMessage().isNetLocked(GameMessage.锁_邮件)) {
//			return;
//		}
//	}

	/**
	 * 邮件的详细信息界面
	 */
	DWFrame m_information_Frame = null;
	DWBackground m_xq_xbj;

	DWLabel m_xq_title_lb;
	DWLabel m_xq_sendname_lb;
	DWLabel m_xq_text_lb;
	DWLabel m_xq_item_lb;
	DWLabel m_xq_money_lb;

	DWTextbox m_xq_title_tb;
	DWTextbox m_xq_sendname_tb;
	DWTextbox m_xq_text_tb;
	DWGrid m_xq_item_grid;
	DWTextbox m_xq_money_tb;

	DWButton m_xq_but[];
	Bitmap m_cr_but_3 = null;
	Bitmap m_cr_but_4 = null;
	String m_but_name[] = new String[] { "收取附件", "回复信件", "删除邮件" };
	String m_reply_name = null;

	public void MailInformation()
	{
		if (DWControlsManager.getInstance().contains(m_information_Frame)) {
			if (m_information_Frame != null) {
				DWControlsManager.getInstance().removeControl(m_information_Frame);
			}
		}
		// ////画布（大背景）
		m_information_Frame = new DWFrame(DWFrame.FRAME_TYPE_HALF_RIGHT,
				true);
		m_information_Frame.setClickClose(false);
		// /////标题
		DWTitle m_xq_tit = new DWTitle("", m_information_Frame);
		m_tit_shouxin_ima = new DWImageBox(m_cr_tit_shouxin);
		m_tit_shouxin_ima.setNearAnchor(m_xq_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);

		// //退出图片按钮
		DWImageBox m_xq_tuichu_ima = new DWImageBox(m_cr_tuichu);
		m_xq_tuichu_ima.setNearAnchorUn(m_xq_tit, Tools.RIGHT_VCENTER,
				Tools.RIGHT_VCENTER, 0, 0);
		m_xq_tuichu_ima.addListener(m_xq_tuichu_lis);
		m_xq_tuichu_ima.setTouchZoomIn(40, 40);
		// //小背景
		///左右15像素，上下20像素
		m_xq_xbj = new DWBackground(
				m_information_Frame.getShowWidth() - 20,
				m_information_Frame.getShowHeight() - (m_mail_tit.getShowHeight() - 20) - 40);
		m_xq_xbj.setNearAnchor(m_information_Frame, Tools.LEFT_TOP,
				Tools.LEFT_TOP, 10, 20 + (m_mail_tit.getShowHeight() - 20));
		////////标题
		m_xq_title_lb = new DWLabel("标题");
		m_xq_title_lb.setShowWideHigh(m_xq_title_lb.getShowWidth(), DWFont.getDefaultFont().getHeight()+5);
		int m_y  = (m_xq_xbj.getShowHeight()-m_xq_title_lb.getShowHeight()*3-m_cr_grid.getHeight()-m_cr_but1.getHeight()-(m_xq_xbj.getShowHeight()-10) / 3-5)/6;
		m_xq_title_lb.setNearAnchor(m_xq_xbj, Tools.LEFT_TOP, Tools.LEFT_TOP, 15, m_y);
		m_xq_title_lb.setBackgroundColor(Tools.ALPHA);
		m_xq_title_lb.setTextColor(0xFFFFBB11);
		////////标题文本框
		if (m_present != null && m_present.length >= 50)
		{
			m_xq_title_tb = new DWTextbox(m_present[m_listbox.getTouchIndex() + m_present.length - 50].m_title, 10*DWFont.getDefaultFont().getFontSize());
		}
		else
		{
			m_xq_title_tb = new DWTextbox(m_present[m_listbox.getTouchIndex()].m_title, 10*DWFont.getDefaultFont().getFontSize());
		}
		m_xq_title_tb.setNearAnchor(m_xq_title_lb, Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 0);

		////////发件人
		////////发件人标签
		m_xq_sendname_lb = new DWLabel("发件人");
		m_xq_sendname_lb.setShowWideHigh(m_xq_sendname_lb.getShowWidth(), DWFont.getDefaultFont().getHeight()+5);
		m_xq_sendname_lb.setNearAnchor(m_xq_title_lb, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, m_y);
		m_xq_sendname_lb.setBackgroundColor(Tools.ALPHA);
		m_xq_sendname_lb.setTextColor(0xFFFFBB11);
		////////发件人输入框
		if (m_present != null && m_present.length >= 50)
		{
			m_xq_sendname_tb = new DWTextbox(m_present[m_listbox.getTouchIndex() + m_present.length - 50].m_sendName,8*DWFont.getDefaultFont().getFontSize());
		}
		else
		{
			m_xq_sendname_tb = new DWTextbox(m_present[m_listbox.getTouchIndex()].m_sendName,8*DWFont.getDefaultFont().getFontSize());
		}
		
		m_xq_sendname_tb.setNearAnchor(m_xq_sendname_lb, Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 0);

		////////内容
		////////内容标签
		m_xq_text_lb = new DWLabel("内容");
		m_xq_text_lb.setShowWideHigh(m_xq_text_lb.getShowWidth(), DWFont.getDefaultFont().getHeight()+5);
		m_xq_text_lb.setNearAnchor(m_xq_sendname_lb, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, m_y);
		m_xq_text_lb.setBackgroundColor(Tools.ALPHA);
		m_xq_text_lb.setTextColor(0xFFFFBB11);
		////////内容输入框
		if (m_present != null && m_present.length >= 50)
		{
			
			m_xq_text_tb = new DWTextbox(m_present[m_listbox.getTouchIndex() + m_present.length - 50].m_content, m_xq_xbj.getShowWidth() - 30,(m_xq_xbj.getShowHeight()-10) / 3);
		}
		else
		{
			m_xq_text_tb = new DWTextbox(m_present[m_listbox.getTouchIndex()].m_content, m_xq_xbj.getShowWidth() - 30,(m_xq_xbj.getShowHeight()-10) / 3);
		}
		m_xq_text_tb.setNearAnchor(m_xq_text_lb, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);

		////////附件
		////////附件标签
		m_xq_item_lb = new DWLabel("附件");
		m_xq_item_lb.setShowWideHigh(m_xq_item_lb.getShowWidth(), DWFont.getDefaultFont().getHeight()+5);
		m_xq_item_lb.setBackgroundColor(Tools.ALPHA);
		m_xq_item_lb.setTextColor(0xFFFFBB11);
		////////附件格子
		m_xq_item_grid = new DWGrid(m_cr_grid);
		m_xq_item_grid.setDarg(false);
		if (m_present != null && m_present.length >= 50)
		{
		
			if (m_present[m_listbox.getTouchIndex() + m_present.length - 50].m_item != null) {
				m_xq_item_grid.addObject(m_present[m_listbox.getTouchIndex() + m_present.length - 50].m_item);
			}
		}
		else
		{
			if (m_present[m_listbox.getTouchIndex()].m_item != null) {
				m_xq_item_grid.addObject(m_present[m_listbox.getTouchIndex()].m_item);
			}
		}
		
		m_xq_item_lb.setNearAnchor(m_xq_text_tb, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, m_xq_item_grid.getShowHeight()
				- m_xq_item_lb.getShowHeight() + m_y);
		m_xq_item_grid.setNearAnchor(m_xq_item_lb, Tools.LEFT_BOTTOM, Tools.RIGHT_BOTTOM, 10, 0);
		m_xq_item_grid.addListener(new DWListener() {

			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				if ((Item) m_xq_item_grid.m_data != null)
				{
					DWGameManager.getInstance().getSendMessage()
							.sendSeeItemInfos(((Item) m_xq_item_grid.m_data).m_guid,
									((Item) m_xq_item_grid.m_data).m_key);
					Tools.debugPrintln("guid:" + ((Item) m_xq_item_grid.m_data).m_guid);
				}
			}
		});

		DWLabel m_item_l = new DWLabel("道具");
		if (m_xq_item_grid.m_data != null) {
			m_item_information_text = new DWTextbox(((Item) m_xq_item_grid.m_data).m_name + " × "
					+ ((Item) m_xq_item_grid.m_data).m_num, 200, 2 * m_item_l.getShowHeight());
		}
		else {
			m_item_information_text = new DWTextbox("", 200, 2 * m_item_l.getShowHeight());
		}
		m_item_information_text.setNearAnchor(m_xq_item_grid, Tools.LEFT_BOTTOM, Tools.RIGHT_BOTTOM, 5, 0);

		////////金钱
		////////金钱标签
		m_xq_money_lb = new DWLabel("金钱");
		m_xq_money_lb.setShowWideHigh(m_send_money_lb.getShowWidth(), 30);
		m_xq_money_lb.setNearAnchor(m_xq_item_lb, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 10);
		m_xq_money_lb.setBackgroundColor(Tools.ALPHA);
		m_xq_money_lb.setTextColor(0xFFFFBB11);
		////////金钱输入框
		if (m_present != null && m_present.length >= 50)
		{
			if (m_present[m_listbox.getTouchIndex() + m_present.length - 50].m_money != 0) {
				m_xq_money_tb = new DWTextbox(Long.toString(m_present[m_listbox.getTouchIndex() + m_present.length - 50].m_money), 200);
			}
			else {
				m_xq_money_tb = new DWTextbox("", 200);
			}
		}
		else
		{
			if (m_present[m_listbox.getTouchIndex()].m_money != 0) {
				m_xq_money_tb = new DWTextbox(Long.toString(m_present[m_listbox.getTouchIndex()].m_money), 200);
			}
			else {
				m_xq_money_tb = new DWTextbox("", 200);
			}
		}
		
		m_xq_money_tb.setNearAnchor(m_xq_money_lb, Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 0);

		m_information_Frame.addControl(m_xq_tit);
		m_information_Frame.addControl(m_tit_shouxin_ima);
		m_information_Frame.addControl(m_xq_tuichu_ima);
		m_information_Frame.addControl(m_xq_xbj);
		m_information_Frame.addControl(m_xq_title_lb);
		m_information_Frame.addControl(m_xq_title_tb);
		m_information_Frame.addControl(m_xq_sendname_lb);
		m_information_Frame.addControl(m_xq_sendname_tb);
		m_information_Frame.addControl(m_xq_text_lb);
		m_information_Frame.addControl(m_xq_text_tb);
		m_information_Frame.addControl(m_xq_item_lb);
		m_information_Frame.addControl(m_xq_item_grid);
		m_information_Frame.addControl(m_item_information_text);
//		m_information_Frame.addControl(m_xq_money_lb);
//		m_information_Frame.addControl(m_xq_money_tb);

		////按钮
		m_xq_but = new DWButton[m_but_name.length];
		for (int m_but_index = 0; m_but_index < m_but_name.length; m_but_index++) {
			m_xq_but[m_but_index] = new DWButton(m_but_name[m_but_index], m_cr_but1);
			m_xq_but[m_but_index].setDownImage(m_cr_but12);
			if (m_but_index == 0) {
				m_xq_but[m_but_index].setNearAnchor(m_xq_xbj, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM,
						(m_xq_xbj.getShowWidth() - 3 * m_xq_but[m_but_index].getShowWidth()) / 4, -m_y);
				m_xq_but[m_but_index].addListener(m_xq_but_0_lis);
				
			}
			else if (m_but_index == 1) {
				m_xq_but[m_but_index].setNearAnchor(m_xq_but[m_but_index - 1], Tools.LEFT_BOTTOM, Tools.RIGHT_BOTTOM,
						(m_xq_xbj.getShowWidth() - 3 * m_xq_but[m_but_index].getShowWidth()) / 4, 0);
				m_xq_but[m_but_index].addListener(m_xq_but_1_lis);
			}
			else {
				m_xq_but[m_but_index].setNearAnchor(m_xq_but[m_but_index - 1], Tools.LEFT_BOTTOM, Tools.RIGHT_BOTTOM,
						(m_xq_xbj.getShowWidth() - 3 * m_xq_but[m_but_index].getShowWidth()) / 4, 0);
				m_xq_but[m_but_index].addListener(m_xq_but_2_lis);
			}
			m_information_Frame.addControl(m_xq_but[m_but_index]);
		}

		DWControlsManager.getInstance().addControl(m_information_Frame);
	}

	public void init()
	{
		// 加载图片
		m_cr_tit = UIWindows.createImage("/img/newui/youjian_1.gnp");
		m_cr_tit_shouxin = UIWindows.createImage("/img/newui/youjian_1.gnp");
		m_cr_tab_1 = UIWindows.createImage("/img/newui/biaoqianye_1.gnp");// 标签页点击前图片
		m_cr_tab_2 = UIWindows.createImage("/img/newui/biaoqianye_2.gnp");// 标签页点击后图片
		m_cr_tuichu = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");// 叉键退出
		m_cr_choose_ture = UIWindows.createImage("/img/newui/xuanzhonganniu_1.gnp");////单选被选中的图片
		m_cr_choose_false = UIWindows.createImage("/img/newui/xuanzhonganniu_2.gnp");//单选没被选的图片
		m_cr_mail_1 = UIWindows.createImage("/img/newui/xiaoliwu_1.gnp"); ///有金钱或者道具时的图片提示
		m_cr_mail_2 = UIWindows.createImage("/img/newui/mail_2.gnp");/////未读的邮件的图片提示
		m_cr_but_3 = UIWindows.createImage("/img/newui/anniu_2.gnp");//小按钮图片
		m_cr_but_4 = UIWindows.createImage("/img/newui/anniu_2ax.gnp");
		m_cr_grid = UIWindows.createImage("/img/newui/wupinlan.gnp");///道具格子无道具的时候的图片
		m_cr_but1 = UIWindows.createImage("/img/newui/anniu_5.gnp");
		m_cr_but12 = UIWindows.createImage("/img/newui/anniu_5ax.gnp");
		m_cr_fy_1 = UIWindows.createImage("/img/newui/haoyoufyan_2.gnp");///个数翻页
		m_cr_fy_2 = UIWindows.createImage("/img/newui/haoyoufyan_1.gnp");
		m_cr_gm_but = UIWindows.createImage("/img/newui/anniu_6.gnp");//客服的发送按钮
		m_cr_gm_but_anxia = UIWindows.createImage("/img/newui/anniu_6ax.gnp");
		m_cr_shuaxin = UIWindows.createImage("/img/newui/shuaxin_1.gnp");//新邮件刷新
		m_cr_shuaxin_xia = UIWindows.createImage("/img/newui/shuaxin_2.gnp");
	}

	public void Updata()
	{
		m_type = MailItem.收件显示_全部;
		if (m_sendMail == null) {
			Tools.debugPrintln("m_sendMail=NULL");
		}
		else {
			m_sendMail.clear(null);
		}
	}

	public void open(byte index)
	{
		// 开启方法
		switch (index) {
			case 0:
				Mail();
				break;
		}
	}

	public void close(byte index)
	{
		// 关闭方法
		AllCancleSelect(MailItem.收件显示_全部);
	}

	public void dispose()
	{
		// 移除方法

	}

	/**
	 * 创建邮件
	 * */
	public static MailItem recvMail(DataInputStream dis) throws IOException
	{
		MailItem mail = new MailItem();
		mail.m_id = dis.readLong();//邮件ID
		mail.m_state = dis.readByte();//邮件状态 0未读 1已读
		mail.m_title = dis.readUTF();//邮件标题
		mail.m_time = MailItem.getData(dis.readLong());//时间
		mail.m_sendName = dis.readUTF();//发件人名字
		mail.m_content = dis.readUTF();//邮件正文
		mail.m_money = dis.readLong();//附件金钱		
		byte itemSize = dis.readByte();//附件道具数量
		Tools.debugPrintln("itemSize=" + itemSize);
		if (itemSize > 0) {
			long itemId = dis.readLong();//道具ID
			Tools.debugPrintln("itemId=" + itemId);
			String name = dis.readUTF();//道具名称
			int num = dis.readInt();//数量
			short iconID = dis.readShort();//图标ID
			byte Quality = dis.readByte();//稀有度
			mail.m_item = new Item();
			mail.m_item.m_guid = itemId;
			mail.m_item.m_name = name;
			mail.m_item.m_num = num;
			mail.m_item.m_iconId = iconID;
			mail.m_item.m_quality = Quality;
			mail.m_item.m_pinzhi = IconManger.getInstance().getPinzhi(Quality);
			mail.m_item.m_icon = IconManger.getInstance().getIcon(iconID);
		}
		return mail;
	}

	/**
	 * 接收新邮件
	 * */
	public void recvRequestNewMails(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("进入新邮件的接收方法。");
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_邮件);
		short size = dis.readShort();//邮件总数
		Tools.debugPrintln("新邮件的邮件长度" + size);
		CopyOnWriteArrayList<MailItem> array = new CopyOnWriteArrayList<MailItem>();
		for (int i = 0; i < size; i++) {
			MailItem mail = recvMail(dis);
			if (mail != null) {
				array.add(mail);
			}
		}
		if (DWGameManager.getInstance().m_role.m_recvMails != null) {
			Tools.debugPrintln("角色邮件的邮件长度(合并之前的长度):" + DWGameManager.getInstance().m_role.m_recvMails.size());
			for (int i = 0; i < DWGameManager.getInstance().m_role.m_recvMails.size(); i++) {
				MailItem item = DWGameManager.getInstance().m_role.m_recvMails.get(i);
				array.add(item);
			}
			DWGameManager.getInstance().m_role.m_recvMails.clear();
		}
		else {
			Tools.debugPrintln("NULL");
		}
		DWGameManager.getInstance().m_role.m_recvMails = array;
		Tools.debugPrintln("合并以后的邮件长度=" + array.size());
		array = null;
		//下面创建界面
		if (DWControlsManager.getInstance().contains(m_mail_Frame))
		{
			UpdataMail(m_type);
			if(!UIWindows.getInstance().m_main.m_tishi_mail_flag)
			{
				UIWindows.getInstance().m_main.m_tishi_mail_flag = true;
			}
		}
		else if (!DWControlsManager.getInstance().contains(m_mail_Frame))
		{
			return;
		}
		if(size==0)
		{
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "亲，您没有新邮件哦。");
		}
	}

	/**
	 * @exception 获取附件是否成功
	 * */
	public void recvGetMailAnnex(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_邮件);
		byte state = dis.readByte();//提取附件是否成功
		Tools.debugPrintln("state:" + state);
		if (state == 1) {//成功
			long maiid = dis.readLong();//邮件ID
			long id = dis.readLong();//道具ID
			Tools.debugPrintln("id=" + id);
			CopyOnWriteArrayList<MailItem> array = GetMails();
			for (MailItem mail : array) {
				if (mail.m_id == maiid) {
					if (mail.m_item != null && mail.m_item.m_guid == id) {
						mail.m_item = null;
						mail.m_money = 0;
						break;
					}
				}
			}
			if (m_present != null && m_present.length >= 0)
			{
				if (m_present.length > 50)
				{
					for (int i = (m_present.length - 50); i < m_present.length; i++)
					{
						if (m_present[i].m_id == maiid)
						{
							m_xq_item_grid.m_data = null;
							m_item_information_text.setText("");
							m_xq_money_tb.setText("");
							m_present[i].m_item = null;
							m_present[i].m_money = 0;
							m_lsi[i].removeControl(m_mail_1[i]);
							Tools.debugPrintln("删除第" + i + "个。");
							Tools.debugPrintln("选中的第" + m_listbox.getTouchIndex() + "个");
							break;
						}
					}
				}
				else
				{
					for (int i = 0; i < m_present.length; i++)
					{
						if (m_present[i].m_id == maiid)
						{
							m_xq_item_grid.m_data = null;
							m_item_information_text.setText("");
							m_xq_money_tb.setText("");
							m_present[i].m_item = null;
							m_present[i].m_money = 0;
							m_lsi[i].removeControl(m_mail_1[i]);
							Tools.debugPrintln("删除第" + i + "个。");
							Tools.debugPrintln("选中的第" + m_listbox.getTouchIndex() + "个");
							break;
						}
					}
				}
			}
//			if (m_present[m_listbox.getTouchIndex()].m_id == maiid) {
//				m_xq_item_grid.m_data = null;
//				m_item_information_text.setText("");
//				m_xq_money_tb.setText("");
//				m_present[m_listbox.getTouchIndex()].m_item = null;
//				m_present[m_listbox.getTouchIndex()].m_money = 0;
//				m_lsi[m_listbox.getTouchIndex()].removeControl(m_mail_1[m_listbox.getTouchIndex()]);
//			}
			Tools.debugPrintln("获取附件成功。");
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "恭喜您，成功获取附件。");
			UpdataMail(m_type);
		}
	}

	/**
	 * @exception 发送邮件是否成功
	 * */
	public void recvSendMail(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_邮件);
		byte state = dis.readByte();//发送邮件是否成功
		//做移除发送邮件
		if (state == 0) {//失败
			//String reason = dis.readUTF();
			return;
		}
		m_sendMail.clear(null);
		m_send_tit_ib.setText("");
		m_send_content_ib.setText("");
		m_item_text.setText("");
		m_send_item_grid.m_data = null;
		m_send_money_ib.setText("");
		m_send_GM_tit_ib.setText("");
		m_send_GM_content_ib.setText("");
		DWGameManager.getInstance().showToast("恭喜您，邮件已经发送成功！", 1000);
	}

	/**
	 * @exception 返回角色收件箱邮件数据
	 * */
	public CopyOnWriteArrayList<MailItem> GetMails()
	{
		return DWGameManager.getInstance().m_role.m_recvMails;
	}

	/**
	 * 删除邮箱指定邮件
	 * @param MailItem 邮件对象
	 * */
	public void DeleteMail(MailItem mail)
	{
		CopyOnWriteArrayList<MailItem> array = GetMails();
		CopyOnWriteArrayList<MailItem> del = new CopyOnWriteArrayList<MailItem>();
		for (MailItem m : array) {
			if (m.equals(mail)) {
				array.remove(m);
				del.add(m);
				break;
			}
		}
		DWGameManager.getInstance().getSendMessage().sendRequestDeleteMails(del);
		del.clear();
		del = null;
		UpdataMail(m_type);
	}

	/**
	 * @exception 删除邮件
	 * @param type 邮箱显示类型
	 * */
	public void DeleteMail()
	{
		CopyOnWriteArrayList<MailItem> array = new CopyOnWriteArrayList<MailItem>();
		if (GetMails() != null && GetMails().size() >= 0)
		{
			if (DWGameManager.getInstance().m_role.m_recvMails.size() >= 50)
			{
				for (int i=DWGameManager.getInstance().m_role.m_recvMails.size()-50 ; i < DWGameManager.getInstance().m_role.m_recvMails.size(); i++)
				{
					array.add(GetMails().get(i));
				}
			}
			else
			{
				array = GetMails();
			}
		}
		if (array != null) {
			CopyOnWriteArrayList<MailItem> del = new CopyOnWriteArrayList<MailItem>();
			Tools.debugPrintln("多个删除邮件的时候的删除邮箱长度：" + m_recive.size());
			for (MailItem mail : array) {
				Long key = (Long) mail.m_id;
				if (m_recive.containsKey(key)) {
					m_recive.remove(key);
					del.add(mail);
					array.remove(mail);
					GetMails().remove(mail);
				}
			}
			DWGameManager.getInstance().getSendMessage().sendRequestDeleteMails(del);
			Tools.debugPrintln("发送删除的邮件的长度：" + del.size());
			del.clear();
			del = null;
			UpdataMail(m_type);
		}
	}

	/**
	 * @exception 全部选择添加到删除列表
	 * @param 当前选择的显示类型
	 * */
	public void AllSelectAddToRecive(byte type)
	{
		CopyOnWriteArrayList<MailItem> array = GetMails();
		if (type == MailItem.收件显示_未读) {
			for (MailItem mail : array) {
				if (mail.m_state == MailItem.状态_未读) {
					AddRecive(mail);
				}
			}
		}
		else {
			for (MailItem mail : array) {
				AddRecive(mail);
			}
		}
	}

	/**
	 * @exception 勾选当前邮件
	 * */
	public void SelectMail(MailItem mail)
	{
		mail.m_select = true;
		AddRecive(mail);
	}

	/**
	 * @exception 取消勾选当前邮件
	 * */
	public void CancelSelectMail(MailItem mail)
	{
		mail.m_select = false;
		DelRecive(mail);
	}

	/**
	 * @exception 全部取消勾选邮件
	 * */
	public void AllCancleSelect(byte type)
	{
		CopyOnWriteArrayList<MailItem> array = GetMails();
		for (MailItem mail : array) {
			CancelSelectMail(mail);
		}
	}

	/**
	 * @exception 添加到删除列表
	 * */
	public void AddRecive(MailItem mail)
	{
		Long key = (Long) mail.m_id;
		if (!m_recive.containsKey(key)) {
			m_recive.put(key, mail);
		}
	}

	/**
	 * @exception 在删除列表中删除
	 * */
	public void DelRecive(MailItem mail)
	{
		Long key = (Long) mail.m_id;
		if (m_recive.containsKey(key)) {
			m_recive.remove(key);
		}
	}

	/**
	 * @exception 刷新邮箱内容到临时数组
	 * @param type 邮箱类型
	 * */
	DWCheckbox m_checkbox[];
	DWImageBox m_mail_1[];
	DWImageBox m_mail_2[];

	public void UpdataMail(byte type)
	{
		CopyOnWriteArrayList<MailItem> array = GetMails();
		Tools.debugPrintln("UpdataMail array.size=" + array.size());
		CopyOnWriteArrayList<MailItem> recv = new CopyOnWriteArrayList<MailItem>();
		if (type == MailItem.收件显示_未读) {
			if (array.size() >= 50)
			{
				for (int i = (array.size() - 50); i < array.size(); i++)
				{
					MailItem item = array.get(i);
					if (item.m_state == MailItem.状态_未读) {
						recv.add(item);
					}
				}
			}
			else
			{
				for (MailItem item : array) {
					if (item.m_state == MailItem.状态_未读) {
						recv.add(item);
					}
				}
				///和上面的for循环式一个意思、
			}
		}
		else {
			recv = array;
		}
		Tools.debugPrintln("recv size=" + recv.size());
		if (recv != null && recv.size() > 0) {
			int size = recv.size();
			Tools.debugPrintln("size:" + size);
			m_present = null;
			m_lsi = null;
			m_present = new MailItem[size];
			m_lsi = new DWListSubItem[size];
			m_listbox.removeAllSubItem();
			m_listbox.setShowBackgroundRect(true);
			m_mail_2 = new DWImageBox[size];
			m_mail_1 = new DWImageBox[size];
			m_checkbox = new DWCheckbox[size];
			Tools.debugPrintln("m_present的长度：" + m_present.length);
			if (size > 50)
			{
				Tools.debugPrintln("从第" + (recv.size() - 50) + "封开始。");
				for (int i = (recv.size() - 50); i < recv.size(); i++) {
					m_present[i] = recv.get(i);
					m_lsi[i] = new DWListSubItem();
					m_lsi[i].setAutoWideHigh(false);
					m_lsi[i].setShowWideHigh(m_listbox.getShowWidth(), 3 * m_l.getShowHeight());
					m_checkbox[i] = new DWCheckbox();
					m_checkbox[i].setChecked(false);
					m_checkbox[i].setNearAnchor(m_lsi[i], Tools.LEFT_VCENTER, Tools.LEFT_VCENTER, 0, 0);
					m_checkbox[i].addListener(m_checkbox_lis);
					m_lsi[i].addControls(m_checkbox[i]);

					if (m_present[i].m_state == MailItem.状态_未读) {
						m_mail_2[i] = new DWImageBox(m_cr_mail_2);
						m_mail_2[i].setNearAnchor(m_lsi[i], Tools.RIGHT_VCENTER,
								Tools.RIGHT_VCENTER,
								-m_cr_mail_1.getWidth(), 0);
						m_lsi[i].addControls(m_mail_2[i]);
					}
					if (m_present[i].m_item != null || m_present[i].m_money > 0) {
						m_mail_1[i] = new DWImageBox(m_cr_mail_1);
						m_mail_1[i].setNearAnchor(m_lsi[i], Tools.RIGHT_VCENTER,
								Tools.RIGHT_VCENTER, 0, 0);
						m_lsi[i].addControls(m_mail_1[i]);
					}

					m_textbox = new DWLabel[m_stringlab.length];
					for (int m_tb_size_1 = 0; m_tb_size_1 < m_textbox.length; m_tb_size_1++) {
						if (m_tb_size_1 == 0) {
							m_textbox[m_tb_size_1] = new DWLabel(m_present[i].m_title);
							m_textbox[m_tb_size_1].setNearAnchor(m_checkbox[i], Tools.LEFT_VCENTER,
									Tools.RIGHT_VCENTER, 0, 0);
						}
						else if (m_tb_size_1 == 1) {
							m_textbox[m_tb_size_1] = new DWLabel(m_present[i].m_sendName);
							m_textbox[m_tb_size_1].setNearAnchor(m_textbox[m_tb_size_1 - 1], Tools.LEFT_TOP,
									Tools.RIGHT_TOP, 0, 0);
						}
						else {
							m_textbox[m_tb_size_1] = new DWLabel(m_present[i].m_time);
							m_textbox[m_tb_size_1].setNearAnchor(m_textbox[m_tb_size_1 - 1], Tools.LEFT_TOP,
									Tools.RIGHT_TOP, 0, 0);
						}
						///与每个标签  左右0，上10
						m_textbox[m_tb_size_1].setShowWideHigh((m_listbox.getShowWidth() - m_cr_mail_1.getWidth()
								- m_cr_mail_2.getWidth() - m_checkbox[i].getShowWidth()) / 3, 3 * m_l.getShowHeight());
						m_textbox[m_tb_size_1].setBackgroundColor(Tools.ALPHA);
						final int m_index = i;
						m_textbox[m_tb_size_1].addListener(new DWListener() {

							public void OnDoubleClick()
							{
							}

							public void OnClick()
							{
								m_listbox.setShowBackgroundRect(true);
								Listener(m_index);
							}
						});
						m_lsi[i].addControls(m_textbox[m_tb_size_1]);
						m_textbox[m_tb_size_1].setFont(DWFont.getFont(DWFont.getDefaultFont().getFontSize()*80/100));
						m_textbox[m_tb_size_1].nameToContents();
					}
					m_listbox.addSubItem(m_lsi[i]);
				}
			}
			else if (size <= 50)
			{
				for (int i = 0; i < size; i++) {
					m_present[i] = recv.get(i);
					m_lsi[i] = new DWListSubItem();
					m_lsi[i].setAutoWideHigh(false);
					m_lsi[i].setShowWideHigh(m_listbox.getShowWidth(), 3 * m_l.getShowHeight());
					m_checkbox[i] = new DWCheckbox();
					m_checkbox[i].setChecked(false);
					m_checkbox[i].setNearAnchor(m_lsi[i], Tools.LEFT_VCENTER, Tools.LEFT_VCENTER, 0, 0);
					m_checkbox[i].addListener(m_checkbox_lis);
					m_lsi[i].addControls(m_checkbox[i]);

					if (m_present[i].m_state == MailItem.状态_未读) {
						m_mail_2[i] = new DWImageBox(m_cr_mail_2);
						m_mail_2[i].setNearAnchor(m_lsi[i], Tools.RIGHT_VCENTER,
								Tools.RIGHT_VCENTER,
								-m_cr_mail_1.getWidth(), 0);
						m_lsi[i].addControls(m_mail_2[i]);
					}
					if (m_present[i].m_item != null || m_present[i].m_money > 0) {
						m_mail_1[i] = new DWImageBox(m_cr_mail_1);
						m_mail_1[i].setNearAnchor(m_lsi[i], Tools.RIGHT_VCENTER,
								Tools.RIGHT_VCENTER, 0, 0);
						m_lsi[i].addControls(m_mail_1[i]);
					}

					m_textbox = new DWLabel[m_stringlab.length];
					for (int m_tb_size_1 = 0; m_tb_size_1 < m_textbox.length; m_tb_size_1++) {
						if (m_tb_size_1 == 0) {
							m_textbox[m_tb_size_1] = new DWLabel(m_present[i].m_title);
							m_textbox[m_tb_size_1].setNearAnchor(m_checkbox[i], Tools.LEFT_VCENTER,
									Tools.RIGHT_VCENTER, 0, 0);
						}
						else if (m_tb_size_1 == 1) {
							m_textbox[m_tb_size_1] = new DWLabel(m_present[i].m_sendName);
							m_textbox[m_tb_size_1].setNearAnchor(m_textbox[m_tb_size_1 - 1], Tools.LEFT_TOP,
									Tools.RIGHT_TOP, 0, 0);
						}
						else {
							m_textbox[m_tb_size_1] = new DWLabel(m_present[i].m_time);
							m_textbox[m_tb_size_1].setNearAnchor(m_textbox[m_tb_size_1 - 1], Tools.LEFT_TOP,
									Tools.RIGHT_TOP, 0, 0);
						}
						///与每个标签  左右0，上10
						m_textbox[m_tb_size_1].setShowWideHigh((m_listbox.getShowWidth() - m_cr_mail_1.getWidth()
								- m_cr_mail_2.getWidth() - m_checkbox[i].getShowWidth()) / 3, 3 * m_l.getShowHeight());
						m_textbox[m_tb_size_1].setBackgroundColor(Tools.ALPHA);
						final int m_index = i;
						m_textbox[m_tb_size_1].addListener(new DWListener() {

							public void OnDoubleClick()
							{
							}

							public void OnClick()
							{
								m_listbox.setShowBackgroundRect(true);
								Listener(m_index);
							}
						});
						m_lsi[i].addControls(m_textbox[m_tb_size_1]);
						m_textbox[m_tb_size_1].setFont(DWFont.getFont(DWFont.getDefaultFont().getFontSize()*80/100));
						m_textbox[m_tb_size_1].nameToContents();
					}
					m_listbox.addSubItem(m_lsi[i]);
				}
			}
		}
		else {
			m_present = null;
			m_listbox.removeAllSubItem();
			if (DWControlsManager.getInstance().contains(m_mail_Frame))
			{
				if (m_chooseRadioButton.getSelectIndex() == 1)
				{
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "现存邮件中无未读状态邮件。");
				}
			}
		}
		if (DWControlsManager.getInstance().contains(m_mail_Frame))
		{
			m_all_del_but_2.setName("全选");
			m_flag = true;
		}
		recv = null;
	}

	public void logic()
	{
	}

	private DWListener m_checkbox_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			m_listbox.setShowBackgroundRect(false);
			if (m_present != null && m_present.length >= 0)
			{
				if (m_present.length >= 50)
				{
					if (m_checkbox[m_listbox.getTouchIndex() + (m_present.length - 50)].getChecked() == true)
					{
						SelectMail(m_present[m_listbox.getTouchIndex() + (m_present.length - 50)]);
					}
					else
					{
						CancelSelectMail(m_present[m_listbox.getTouchIndex() + (m_present.length - 50)]);
					}
				}
				else
				{
					if (m_checkbox[m_listbox.getTouchIndex()].getChecked() == true)
					{
						SelectMail(m_present[m_listbox.getTouchIndex()]);
					}
					else
					{
						CancelSelectMail(m_present[m_listbox.getTouchIndex()]);
					}
				}
			}
		}
	};

	public void Listener(int i)
	{
		if (m_lsi[i].contains(m_mail_2[i]))
		{
			m_lsi[i].removeControl(m_mail_2[i]);
			Tools.debugPrintln("进入含有新邮件提示的图片的监听。");
		}
		MailInformation();
		m_present[i].m_state = MailItem.状态_已读;
		DWGameManager.getInstance().getSendMessage().sendChangeMailState(m_present[i].m_id);
	}

	private DWListener m_chooseRadioButton_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			if (m_chooseRadioButton.getSelectIndex() == 0)
			{
				if (DWControlsManager.getInstance().contains(m_information_Frame))
				{
					DWControlsManager.getInstance().removeControl(m_information_Frame);
				}
				UpdataMail(MailItem.收件显示_全部);
				m_type = MailItem.收件显示_全部;
			}
			else if (m_chooseRadioButton.getSelectIndex() == 1)
			{
				if (DWControlsManager.getInstance().contains(m_information_Frame))
				{
					DWControlsManager.getInstance().removeControl(m_information_Frame);
				}
				UpdataMail(MailItem.收件显示_未读);
				m_type = MailItem.收件显示_未读;
			}
		}
	};

	private DWListener m_del_1_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			if (m_present != null && m_present.length > 0)
			{
				if (m_present.length >= 50)
				{
					for (int i = (m_present.length - 50); i < m_present.length; i++)
					{
						if (m_checkbox[i].getChecked())
						{
							final DWMessageBox mb = new DWMessageBox("温馨提示", "确定删除邮件？", "确定", "返回");
							DWControlsManager.getInstance().addControl(mb);
							mb.addListener(new DWListener() {

								public void OnDoubleClick()
								{
								}

								public void OnClick()
								{
									if (mb.getResult() == DWMessageBox.SOFTKEY_OK)
									{
										if (DWControlsManager.getInstance().contains(m_information_Frame))
										{
											DWControlsManager.getInstance().removeControl(m_information_Frame);
										}
										DeleteMail();
									}
									else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK)
									{
									}
									DWControlsManager.getInstance().removeControl(mb);
								}
							});
							return;
						}
					}
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "无选中邮件，请选中要删除的邮件。");

				}
				else
				{
					for (int i = 0; i < m_present.length; i++)
					{
						if (m_checkbox[i].getChecked())
						{
							final DWMessageBox mb = new DWMessageBox("温馨提示", "确定删除邮件？", "确定", "返回");
							DWControlsManager.getInstance().addControl(mb);
							mb.addListener(new DWListener() {

								public void OnDoubleClick()
								{
								}

								public void OnClick()
								{
									if (mb.getResult() == DWMessageBox.SOFTKEY_OK)
									{
										if (DWControlsManager.getInstance().contains(m_information_Frame))
										{
											DWControlsManager.getInstance().removeControl(m_information_Frame);
										}
										DeleteMail();
									}
									else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK)
									{
									}
									DWControlsManager.getInstance().removeControl(mb);
								}
							});
							return;
						}
					}
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "无选中邮件，请选中要删除的邮件。");
				}
			}
			else if (m_present == null || m_present.length == 0)
			{
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "暂无邮件，务需删除。");
			}
		}
	};

	private DWListener m_all_del_but_2_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			if (m_flag == true)
			{
				if (m_present != null && m_present.length > 0)
				{
					if (m_present.length >= 50)
					{
						for (int m_setchecked_true = (m_present.length - 50); m_setchecked_true < m_present.length; m_setchecked_true++)
						{
							m_checkbox[m_setchecked_true].setChecked(true);
						}
						AllSelectAddToRecive(m_type);
						m_all_del_but_2.setName("取消");
						m_flag = false;
					}
					else
					{
						for (int m_setchecked_true = 0; m_setchecked_true < m_present.length; m_setchecked_true++)
						{
							m_checkbox[m_setchecked_true].setChecked(true);
						}
						AllSelectAddToRecive(m_type);
						m_all_del_but_2.setName("取消");
						m_flag = false;
					}
				}
				else if (m_present == null || m_present.length == 0)
				{
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "没有邮件，无法全选。");
				}
			}
			else
			{
				if (m_present != null && m_present.length > 0)
				{
					if (m_present.length >= 50)
					{
						for (int m_setchecked_false = (m_present.length - 50); m_setchecked_false < m_present.length; m_setchecked_false++)
						{
							m_checkbox[m_setchecked_false].setChecked(false);
						}
						AllCancleSelect(m_type);
						m_all_del_but_2.setName("全选");
						m_flag = true;
					}
					else
					{
						for (int m_setchecked_false = 0; m_setchecked_false < m_present.length; m_setchecked_false++)
						{
							m_checkbox[m_setchecked_false].setChecked(false);
						}
						AllCancleSelect(m_type);
						m_all_del_but_2.setName("全选");
						m_flag = true;
					}
				}
			}
		}
	};

	private DWListener m_grid_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			Tools.debugPrintln("进入格子监听、");
			UIWindows.getInstance().m_bag.open((byte) 2);
		}
	};

	private DWListener m_send_but_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			if (m_send_tit_ib.getText() == null || m_send_tit_ib.getText().equals(""))
			{
				DWGameManager.getInstance().showToast("标题不能为空。", 1000);
			}
			else
			{
				if (m_send_tit_ib.getText().toString().length() > 9)
				{
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "标题内容的长度不能大于9。");
				}
				else
				{
					if (m_send_recv_ib.getText() == null || m_send_recv_ib.getText().equals(""))
					{
						DWGameManager.getInstance().showToast("收件人不能为空。", 1000);
					}
					else {
						if (m_send_money_ib.getText() != null && !m_send_money_ib.getText().equals(""))
						{
							if (!DWCharsDetection.detectionNumbers(m_send_money_ib.getText()))
							{
								DWGameManager.getInstance().showToast("抱歉，只允许输入数字。", 1000);
							}
							else
							{
								if (DWGameManager.getInstance().m_role.m_gold < Long.parseLong(m_send_money_ib
										.getText()))
								{
									DWGameManager.getInstance().showToast("对不起，您的金币不足，请在您的金钱范围内输入金钱数。", 1000);
								}
								else
								{
									m_sendMail.m_title = m_send_tit_ib.getText();
									m_sendMail.m_recvName = m_send_recv_ib.getText();
									m_sendMail.m_content = m_send_content_ib.getText();
									m_sendMail.m_money = Long.parseLong(m_send_money_ib.getText());
									if (m_send_item_grid.m_data != null)
									{
										m_sendMail.m_item = (Item) m_send_item_grid.m_data;
									}
									DWGameManager.getInstance().getSendMessage().sendMail(m_sendMail);
								}
							}
						}
						else
						{
							m_sendMail.m_title = m_send_tit_ib.getText();
							m_sendMail.m_recvName = m_send_recv_ib.getText();
							m_sendMail.m_content = m_send_content_ib.getText();
							if (m_send_item_grid.m_data != null)
							{
								m_sendMail.m_item = (Item) m_send_item_grid.m_data;
							}
							DWGameManager.getInstance().getSendMessage().sendMail(m_sendMail);
						}
					}
				}
			}
		}
	};

	private DWListener m_add_but_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			UISocial.openUISocialFriendToMail();
		}
	};

	private DWListener m_xq_but_0_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			if (m_xq_item_grid.m_data == null
					&& (m_xq_money_tb.getText() == null || m_xq_money_tb.getText().equals("")))
			{
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "抱歉，您没有可收取的附件。");
			}
			else
			{
				if (m_present.length >= 50)
				{
					DWGameManager.getInstance().getSendMessage().sendRequestGetAnnex(
							m_present[m_listbox.getTouchIndex() + (m_present.length - 50)].m_id);
				}
				else
				{
					DWGameManager.getInstance().getSendMessage().sendRequestGetAnnex(
							m_present[m_listbox.getTouchIndex()].m_id);
				}
			}
		}
	};

	private DWListener m_new_mail_lis = new DWListener() {
		
		public void OnDoubleClick() {
		}
		
		public void OnClick() {
			if(DWControlsManager.getInstance().contains(m_information_Frame))
			{
				DWControlsManager.getInstance().removeControl(m_information_Frame);
			}
			if(m_present != null &&m_present.length>=0)
			{
				if(m_present.length>=50)
				{
					if(m_chooseRadioButton.getSelectIndex() == 0)
					{
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "您邮件的总个数大于或等于50封，请先清理邮件。");
					}
					else if(m_chooseRadioButton.getSelectIndex() == 1)
					{
						Total();
						if(m_state_num>=50)
						{
							DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "您的总邮件中未读邮件个数大于或等于50封。");
							UpdataMail(m_type);
						}
						else if(m_state_num<50)
						{
							DWGameManager.getInstance().getSendMessage().sendRequestNewMails();
						}
					}
				}
				else if(m_present.length<50)
				{
					DWGameManager.getInstance().getSendMessage().sendRequestNewMails();
				}
			}
			else
			{
				DWGameManager.getInstance().getSendMessage().sendRequestNewMails();
			}
		}
	};
	private DWListener m_xq_but_1_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			m_tabcontrol.setSelectPage(1);
			DWControlsManager.getInstance().removeControl(m_information_Frame);
			if (m_present != null && m_present.length >= 0)
			{
				if (m_present.length >= 50)
				{
					m_send_recv_ib.setText(m_present[m_listbox.getTouchIndex() + m_present.length - 50].m_sendName);
				}
				else
				{
					m_send_recv_ib.setText(m_present[m_listbox.getTouchIndex()].m_sendName);
				}
			}
		}
	};
    public boolean m_del_flag = true;
	private DWListener m_xq_but_2_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			final DWMessageBox mb = new DWMessageBox("温馨提示", "确定删除该邮件？", "确定", "返回");
			DWControlsManager.getInstance().addControl(mb);
			mb.addListener(new DWListener() {

				public void OnDoubleClick()
				{
				}

				public void OnClick()
				{
					if (mb.getResult() == DWMessageBox.SOFTKEY_OK)
					{
						if (DWControlsManager.getInstance().contains(m_information_Frame))
						{
							DWControlsManager.getInstance().removeControl(m_information_Frame);
						}
						if (GetMails() != null && GetMails().size() >= 0)
						{
							if (GetMails().size() >= 50)
							{
								DeleteMail(m_present[m_listbox.getTouchIndex() + m_present.length - 50]);
							}
							else
							{
								DeleteMail(m_present[m_listbox.getTouchIndex()]);
							}
						}
					}
					else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK)
					{
					}
					DWControlsManager.getInstance().removeControl(mb);
				}
			});
		}
	};

	private DWListener m_left_lis = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			int m_choose_left = Integer.parseInt(m_choose_ib.getText());

			if (m_choose_left > 0)
			{
				m_choose_left -= 1;
				m_choose_ib.setText(m_choose_left + "");
			}
			else
			{
				m_choose_ib.setText(Integer.toString(((Item) m_send_item_grid.m_data).m_num));
			}
		}
	};

	private DWListener m_right_lis = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			int m_choose_right = Integer.parseInt(m_choose_ib.getText());

			if (m_choose_right >= ((Item) m_send_item_grid.m_data).m_num)
			{
				m_choose_ib.setText("0");
			}
			else
			{
				m_choose_right += 1;
				m_choose_ib.setText(m_choose_right + "");
			}
		}
	};

	private DWListener m_but_1_lis = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			if (m_choose_ib.getText() != null || m_choose_ib.equals(""))
			{
				Item item = (Item) m_send_item_grid.m_data;
				if (item == null) {
					return;
				}
				if (Integer.parseInt(m_choose_ib.getText()) > item.m_num)
				{
					m_choose_ib.setText("0");
				}
				else if (Integer.parseInt(m_choose_ib.getText()) == 0)
				{
					m_item_text.setText("");
					m_send_item_grid.m_data = null;
					DWControlsManager.getInstance().removeControl(m_choose_frame);
				}
				else if (Integer.parseInt(m_choose_ib.getText()) < 0)
				{
					DWGameManager.getInstance().showToast("输入的数量不能小于0。", 1000);
				}

				else
				{
					item.m_num = Integer.parseInt(m_choose_ib.getText());
					DWControlsManager.getInstance().removeControl(m_choose_frame);
					m_item_text.setText(item.m_name + " × " + m_choose_ib.getText());
				}
			}
		}
	};

	private DWListener m_but_2_lis = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			DWControlsManager.getInstance().removeControl(m_choose_frame);
//			m_send_item_grid.m_data = null;
		}
	};

	public void Choose()
	{
		if (m_item_cell == null)
			return;

		m_send_item_grid.addObject(m_item_cell.m_item);
		if (m_item_cell.m_item.m_num < 2) {
			m_item_text.setText(((Item) m_send_item_grid.m_data).m_name + " × 1");
			return;
		}

		m_choose_frame = new DWFrame(300, 150);
		m_choose_frame.setCentre();
		m_choose_frame.setClickClose(false);

		DWTitle m_choose_tit = new DWTitle("选择个数", m_choose_frame);

		DWImageBox m_tuichu_ima_1 = new DWImageBox(m_cr_tuichu);
		m_tuichu_ima_1.setNearAnchorUn(m_choose_tit, Tools.RIGHT_VCENTER,
				Tools.RIGHT_VCENTER, 0, 0);
		m_tuichu_ima_1.addListener(m_tuichu_lis);
		m_tuichu_ima_1.setTouchZoomIn(40, 40);

		m_choose_ib = new DWInputBox(150, 32, m_choose_frame);
		m_choose_ib.setNearAnchor(m_choose_tit, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0,
				(m_choose_frame.getShowHeight() - m_choose_tit.getShowHeight() - m_choose_ib
						.getShowHeight() - m_cr_but1.getHeight() - 10) / 2);
		m_choose_ib.setText(Integer.toString(((Item) m_send_item_grid.m_data).m_num));

		DWImageBox m_choose_ima_left = new DWImageBox(m_cr_fy_1);
		m_choose_ima_left.setNearAnchor(m_choose_ib, Tools.RIGHT_VCENTER, Tools.LEFT_VCENTER, -5, 0);
		m_choose_ima_left.addListener(m_left_lis);

		DWImageBox m_choose_ima_right = new DWImageBox(m_cr_fy_2);
		m_choose_ima_right
				.setNearAnchor(m_choose_ib, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);
		m_choose_ima_right.addListener(m_right_lis);

		DWButton m_choose_but_1 = new DWButton("确定", m_cr_but1);
		m_choose_but_1.setDownImage(m_cr_but12);
		m_choose_but_1.setNearAnchor(m_choose_frame, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM,
				(m_choose_frame.getShowWidth() - 2 * m_cr_but1.getWidth()) / 3, -10);
		m_choose_but_1.addListener(m_but_1_lis);

		DWButton m_choose_but_2 = new DWButton("返回", m_cr_but1);
		m_choose_but_2.setDownImage(m_cr_but12);
		m_choose_but_2.setNearAnchor(m_choose_frame, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM,
				-(m_choose_frame.getShowWidth() - 2 * m_cr_but1.getWidth()) / 3, -10);
		m_choose_but_2.addListener(m_but_2_lis);

		m_choose_frame.addControl(m_choose_tit);
		m_choose_frame.addControl(m_choose_ib);
		m_choose_frame.addControl(m_choose_ima_left);
		m_choose_frame.addControl(m_choose_ima_right);
		m_choose_frame.addControl(m_choose_but_1);
		m_choose_frame.addControl(m_choose_but_2);

		DWControlsManager.getInstance().addControl(m_choose_frame);
	}
	int m_alreay_state_num = 0;//已经读了
	int m_state_num = 0;//还没有读取
	public void Total()
	{
		if(m_present!= null && m_present.length>=0)
		{
			for(int i = (m_present.length-50);i<m_present.length;i++)
			{
				if(m_present[i].m_state == MailItem.状态_已读)
				{
					m_alreay_state_num++;
				}
				else if(m_present[i].m_state == MailItem.状态_未读)
				{
					m_state_num++;
				}
			}
		}
//		else if(m_present.length<50)
//		{
//			for(int i = 0;i<m_present.length;i++)
//			{
//				if(m_present[i].m_state == MailItem.状态_已读)
//				{
//					m_alreay_state_num++;
//				}
//				else if(m_present[i].m_state == MailItem.状态_未读)
//				{
//					m_state_num++;
//				}
//			}
//		}
	}
}
